#include <stdio.h>
#include "test_apis.h"
#include "mvos/mvos_apis.h"
#include "mvt_utilities/mvt_utilities.h"

#define TEST_RUN_SEC    60
#define TEST_DEV2PC     0
#define TEST_NTP        0
#define TEST_SDCARD     0
#define TEST_VIDEO      1
#define TEST_OSD        1
#define TEST_JPEG       1
#define TEST_AUDIO_AO   1
#define TEST_AUDIO_AI   1
#define TEST_ALARM_MD   1
#define TEST_ALARM_HD   1

#if TEST_NTP
mv_void_t test_ntp()
{
    extern mv_s32_t ntpthread_create(mv_void_t);
    ntpthread_create();
}
#endif

mv_void_t test_jpeg()
{
    mvp_video_mjpg_save_file("/tmp/test.jpeg");
}

mv_bool_t serv()
{
    return MV_FALSE;
}

mv_s32_t demo_main()
{
    libmvt_utilities_module_init();

    MVPC_LOG_INF("[DEMO] demo start \n");

    mvp_plat_version();

#if TEST_NTP
    test_ntp();
#endif

#if TEST_DEV2PC
    test_dev2pc();
    return MV_EC_SUCCESS;
#endif

    mvp_plat_source_init();

#if TEST_SDCARD
    mvp_sdcard_mount();
#endif

#if TEST_VIDEO
    test_video_start();
#endif

#if TEST_VIDEO && TEST_OSD
    test_osd_start();
#endif

#if TEST_VIDEO && TEST_JPEG
    test_jpeg();
#endif

#if TEST_AUDIO_AO
    test_audio_ao_start();
#endif

#if TEST_AUDIO_AI
    test_audio_ai_start();
#endif

#if TEST_ALARM_MD
    test_alarm_md_start();
#endif

#if TEST_ALARM_HD
    test_alarm_hd_start();
#endif

    mv_time_t  _t_sts = mvos_time_mono(NULL);
    mv_bool_t  _bl_draw_box = MV_FALSE;

#if TEST_OSD
    _bl_draw_box = MV_TRUE;
#endif

    while(1) {
#if TEST_ALARM_MD || TEST_ALARM_HD
        test_alarm_wait_data(_bl_draw_box);
#endif
        mvos_sleep(1);
        if((mvos_time_mono(NULL) - _t_sts) >= TEST_RUN_SEC) {
            break;
        }
    }

    MVPC_LOG_WAR("[DEMO] exit. \n");

#if TEST_ALARM_MD
    test_alarm_md_stop();
#endif

#if TEST_ALARM_HD
    test_alarm_hd_stop();
#endif

#if TEST_AUDIO_AI
    test_audio_ai_stop();
#endif

#if TEST_AUDIO_AO
    test_audio_ao_stop();
#endif

#if TEST_VIDEO && TEST_OSD
    test_osd_stop();
#endif

#if TEST_VIDEO
    test_video_stop();
#endif

    mvp_plat_source_uninit();
    return MV_EC_SUCCESS;
}

mv_s32_t main()
{
    return demo_main();
}
